<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\User;
use Hash;
use App\Http\Requests\UserInsertRequest;


class userControllers extends Controller
{
   
    public function index()
    {
        return view('index.index');
    }

    public function lu(Request $request)
    {
        // echo 'aaa';
        $username = $request->username;
        $user = User::where('username',$username)->first();
        if(empty($user)){
            return back()->with('info','账号不存在');
        }
        if(Hash::check($request->password,$user->password)) {
            session(['id'=>$user->id]);
            return redirect('/qq')->with('info','登陆成功');
            // echo '22';
        } else {
            return back();
            // echo 2222;
        }
    }
    public function zhuce()
    {
        return view('index.zhuce');
    }

    public function form(UserInsertRequest $request)
    {
        //  $this->validate($request, [
        // 'username' => 'required|regex:/^\w{6,20}$/|unique:users,username',
        // 'password' => 'required|regex:/^\S{6,20}$/|same:passwd',
        // 'email'=>'required|email'
        // ],[
        // 'username.required'=>'用户名必填',
        // 'username.unique'=>'用户名已存在',
        // 'username.regex'=>'用户名格式不正确',
        // 'password.regex'=>'密码格式不正确',
        // 'password.same'=>'两次密码不一样',
        // 'password.required'=>'密码必填',
        // 'email.email'=>'邮箱格式不正确'
        // ]);
         // echo 33;
        $user = new User;
        $user -> username = $request->username;
        $user -> password = Hash::make($request->input('password'));
        // dd($user->password);
        $user -> email = $request->email;
        if($user->save()) {
            return redirect('/deng')->with('info','注册成功！！！！');
        }else{
            return back();
        }
    }

    public function tupian()
    {
        $imgs = User::paginate(3);
        return view('tupian',['touxiang'=>$imgs]);
    }
}


    